//
//  LLMallDoSuccessView.m
//  LoveLove
//
//  Created by 肖兰月 on 2019/4/9.
//  Copyright © 2019 wkf. All rights reserved.
//

#import "LLMallDoSuccessView.h"

@interface LLMallDoSuccessView ()
@property (strong, nonatomic) LLButton *bgCover;
@property (strong, nonatomic) UIView *contentView;
@property (strong, nonatomic) UIImageView *imgView;
@property (strong, nonatomic) UILabel *titleLbl;
@property (strong, nonatomic) UILabel *priceLbl;
@property (strong, nonatomic) LLButton *wechatBtn;
@property (strong, nonatomic) LLButton *qqBtn;
@property (strong, nonatomic) LLButton *weiboBtn;
@end

@implementation LLMallDoSuccessView

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self initSubViews];
    }
    return self;
}

- (void)initSubViews {
    _bgCover = [LLButton new];
    _bgCover.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.5];
    _bgCover.frame = self.bounds;
    [self addSubview:_bgCover];
    
    CGFloat left = LLScreenWidth < 375 ? 30 : 40;
    CGFloat contentW = self.width-left*2;
    _contentView = UIView.new;
    _contentView.frame = CGRectMake(left, (self.height-280)*0.4, contentW, 280);
    _contentView.backgroundColor = UIColor.whiteColor;
    _contentView.layer.cornerRadius = 7;
    _contentView.clipsToBounds = YES;
    [self addSubview:_contentView];
    
    _imgView = [[UIImageView alloc] initWithFrame:CGRectMake((self.width-169)/2.0, _contentView.top-85, 169, 149)];
    _imgView.image = [UIImage imageNamed:@"奖牌"];
    [self addSubview:_imgView];
    
    _titleLbl = [LLInitBaseViewTool labelWithText:nil textColor:LLColorRGB(0) font:18 textAlignment:NSTextAlignmentCenter];
    _titleLbl.frame = CGRectMake(0, 80, _contentView.width, 20);
    [_contentView addSubview:_titleLbl];
    
    _priceLbl = [LLInitBaseViewTool labelWithText:nil textColor:LLColor(214, 27, 21) font:30 textAlignment:NSTextAlignmentCenter];
    _priceLbl.frame = CGRectMake(0, _titleLbl.bottom +10, _contentView.width, 26);
    [_contentView addSubview:_priceLbl];
    
    UILabel *shareLbl = [LLInitBaseViewTool labelWithText:@"继续分享给好友吧" textColor:LLColor(214, 27, 21) font:18 textAlignment:NSTextAlignmentCenter];
    shareLbl.frame = CGRectMake(0, _priceLbl.bottom+5, _contentView.width, 30);
    [_contentView addSubview:shareLbl];
    
    CGFloat btnW = 60;
    CGFloat btnH = btnW + 30;
    CGFloat btnY = shareLbl.bottom + 10;
    CGFloat margin = (self.contentView.width-60*3)/4;
    CGFloat spacing = 10;
    
    _wechatBtn = [LLInitBaseViewTool buttonWithTitle:@"微信群聊" image:@"wechat" titleColor:LLColorRGB(0) font:13];
    _wechatBtn.frame = CGRectMake(margin, btnY, btnW, btnH);
    [_contentView addSubview:_wechatBtn];
    [self verticalCenterImageAndTitle:spacing btn:_wechatBtn];
    [self verticalCenterImageAndTitleWithBtn:_wechatBtn];
    
    _qqBtn = [LLInitBaseViewTool buttonWithTitle:@"QQ" image:@"QQ" titleColor:LLColorRGB(0) font:13];
    _qqBtn.frame = CGRectMake(_wechatBtn.right+margin, btnY, btnW, btnH);
    [_contentView addSubview:_qqBtn];
    [self verticalCenterImageAndTitle:spacing btn:_qqBtn];
    [self verticalCenterImageAndTitleWithBtn:_qqBtn];
    
    _weiboBtn = [LLInitBaseViewTool buttonWithTitle:@"微博" image:@"weibo" titleColor:LLColorRGB(0) font:13];
    _weiboBtn.frame = CGRectMake(_qqBtn.right+margin, btnY, btnW, btnH);
    [_contentView addSubview:_weiboBtn];
    [self verticalCenterImageAndTitle:spacing btn:_weiboBtn];
    [self verticalCenterImageAndTitleWithBtn:_weiboBtn];
}


- (void)setTitle:(NSString *)title {
    _title = title;
    _titleLbl.text = title;
}

- (void)setPrice:(NSString *)price {
    _price = price;
    _priceLbl.text = price;
}

- (void)verticalCenterImageAndTitle:(CGFloat)spacing btn:(UIButton *)btn{
    CGSize imageSize = btn.imageView.frame.size;
    CGSize titleSize = btn.titleLabel.frame.size;
    btn.titleEdgeInsets = UIEdgeInsetsMake(0.0, - imageSize.width, - (imageSize.height + spacing/2), 0.0);
    titleSize = btn.titleLabel.frame.size;
    btn.imageEdgeInsets = UIEdgeInsetsMake(- (titleSize.height + spacing/2), 0.0, 0.0, - titleSize.width);
}

- (void)verticalCenterImageAndTitleWithBtn:(UIButton *)btn{
    //    const int DEFAULT_SPACING = 10.0f;
    [self verticalCenterImageAndTitle:10 btn:btn];
}

@end
